package com.syh.jn.scm.infrastructure.repository.impl.supplier.sale;

import com.syh.core.ddd.infrastructure.repository.AbstractAggregateRepository;
import com.syh.jn.scm.domain.support.entity.History;
import com.syh.jn.scm.domain.support.repository.HistoryRepository;
import com.syh.jn.scm.dto.support.HistoryVo;
import com.syh.jn.scm.infrastructure.repository.model.history.SaleHistoryModel;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

/**
 * Created by soci.song on 2019/1/18.
 */
@Repository("saleHistoryRepositoryImpl")
public class SaleOrderHistoryRepositoryImpl extends AbstractAggregateRepository<History, SaleHistoryModel, Long> implements HistoryRepository {

  @Override
  protected Class getViewObject() {
    return HistoryVo.class;
  }

  /**
   * 根据单据id删除
   *
   * @param id
   */
  @Override
  public void deleteHistorysByOriginalId(Long id) {
    String hql = "delete from SaleHistoryModel where originalId = :originalId";
    Query query = this.hibernateTemplate.getSessionFactory().getCurrentSession().createQuery(hql);
    query.setParameter("originalId", id);
    query.executeUpdate();
  }

  @Override
  public void deleteHistorysByBusinessEntityId(Long id) {
    String hql = "delete from SaleHistoryModel where businessEntityId = :businessEntityId";
    Query query = this.hibernateTemplate.getSessionFactory().getCurrentSession().createQuery(hql);
    query.setParameter("businessEntityId", id);
    query.executeUpdate();
  }
}
